home *** CD-ROM | disk | FTP | other *** search
- (*--------------------------------------------------------------------------*)
- (* *)
- (* Written by Laszlo S. Gonc for Turbo Version 3.0 *)
- (* *)
- (* Can be contacted via Gene Plantz IBBS *)
- (* (312) 885-9557 or (312) 882-4227 *)
- (* *)
- (* The ACCEPT procedure is a variation on the readln command in Turbo *)
- (* Pascal. The main ACCEPT routine uses the following sub-procedures: *)
- (* -- cursorOn *)
- (* -- cursorOff *)
- (* -- get (ch) *)
- (* The procedure allows the programmer to accept certain characters as *)
- (* input at (row,column) for a specified length and exits the procedure *)
- (* if [ESC] was pressed and returns true for the esc boolean value. The *)
- (* type of data entered is determined by the case statement for the *)
- (* datatype of the input. *)
- (* *)
- (* For example, accept (3,1,10,1,string,esc) will accept input at row 3, *)
- (* column 1, length is 10 characters, datatype 1 is defined by the case *)
- (* statement, variable string and if esc was not pressed then esc = false. *)
- (* A default can be used if string is predefined; otherwise let string='' *)
- (* before using accept. *)
- (* *)
- (* If you find this routine of any use, please let me know. Also, if you *)
- (* make any major changes to the code or program logic, please let me *)
- (* know, I am greatly interested in improvements to my routine. *)
- (* *)
- (*--------------------------------------------------------------------------*)
-
- type regPack = record case integer of
- 1 : (AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags: integer);
- 2 : (AL,AH,BL,BH,CL,CH,DL,DH : byte );
- end;
- st80 = string[80];
-
- var cursor : integer;
- regs : regpack;
-
- (*--------------------------------------------------------------------------*)
- (* Procedures to turn the cursor on and off. *)
- (*--------------------------------------------------------------------------*)
- procedure cursorOff;
- begin
- regs.AX := $0300;
- intr ($10,regs);
- cursor := regs.CX;
- regs.AX := $0100;
- regs.CX := $2000;
- intr ($10,regs)
- end;
-
- procedure cursorOn;
- begin
- regs.AX := $0100;
- regs.CX := cursor;
- intr ($10,regs)
- end;
-
- (*--------------------------------------------------------------------------*)
- (* Procedure to read the keyboard (extended scan codes as well). *)
- (*--------------------------------------------------------------------------*)
- procedure get (var ch:char);
- begin
- read (kbd,ch);
- if (ch = #27) and keypressed then
- begin
- read (kbd,ch);
- case ch of
- #15 : ch := ^O; { tab backwards }
- #72 : ch := ^E; { cursor up, control-E }
- #75 : ch := ^S; { cursor left, control-S }
- #77 : ch := ^D; { cursor right, control-D }
- #80 : ch := ^X; { cursor down, control-X }
- #82 : ch := ^V; { insert }
- #83 : ch := ^G; { delete }
- else ch := #00;
- end;
- end;
- end;
-
- (*--------------------------------------------------------------------------*)
- (* Procedure to accept input, format (row,column,size,datatype,string,esc) *)
- (*--------------------------------------------------------------------------*)
- procedure accept (row,col,len,datatype:integer; var temp:st80; var esc:boolean);
- var x : integer;
- ch : char;
- ins : boolean;
- procedure println;
- begin
- cursorOff;
- gotoxy (col,row);
- write (temp);
- clreol;
- gotoxy (x,row);
- cursorOn;
- end;
- procedure format;
- begin
- if x < col + len - 1 then
- begin
- if ins then
- temp := copy (temp,1,x - col) + ch + copy (temp,x - col + 1,col + len - x - 1)
- else temp := copy (temp,1,x - col) + ch + copy (temp,x - col + 2,col + len - x);
- x := x + 1;
- end
- else begin
- if x = col + len - 1 then
- x := x + 1;
- temp := copy (temp,1,len - 1) + ch;
- end;
- end;
- begin
- esc := false;
- ins := false;
- x := col;
- println;
- repeat
- get (ch);
- if ch = #27 then
- begin
- esc := true;
- temp := '';
- exit;
- end;
- case ch of
- #4 : if x < col + length (temp) then
- x := x + 1;
- #7 : temp := copy (temp,1,x - col) + copy (temp,x - col + 2,len);
- #8 : if not (x <= col) then
- begin
- delete (temp,x - col,1);
- x := x - 1;
- end;
- #9 : x := col + length (temp);
- #15 : x := col;
- #19 : if x > col then
- x := x - 1;
- #22 : ins := not (ins);
- else if ch <> #13 then
- case datatype of
- 1 : if ch in [#32..#125]
- then format;
- 2 : if upcase (ch) in ['A','F','S','U']
- then begin
- ch := upcase (ch);
- format;
- end;
- end;
- end;
- println;
- until ch in [#13];
- end;